<?php
/* @var $this \yii\web\View */

/* @var $content string */

use common\components\tools\Html;
use home\assets\Home;
use yii\bootstrap\NavBar;
use common\rewrite\bootstrap\Nav;
use bluezed\scrollTop\ScrollTop;
use kartik\icons\Icon;
use yii\bootstrap\Modal;
use common\components\tools\Url;

Home::register($this);
Icon::map($this);
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
    <meta charset="<?= Yii::$app->charset ?>">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <?= Html::csrfMetaTags() ?>
    <title><?= Html::encode($this->title) ?></title>
    <?php $this->head() ?>
</head>
<body>
<?php $this->beginBody() ?>

<?php if (isset($this->blocks['header']))echo $this->blocks['header']; ?>

<div class="wrap">
    <?php
    NavBar::begin([
        'brandLabel' => Yii::$app->name,
        'brandUrl' => Yii::$app->homeUrl,
        'options' => [
            'class' => 'navbar-inverse navbar-fixed-top',
        ],
    ]);
    $menuItems = [
        ['label' => Yii::t('app', 'Home'), 'url' => ['/site/index']],
        ['label' => Yii::t('app', 'About'), 'url' => ['/site/about']],
        ['label' => Yii::t('app', 'News'), 'url' => ['/docu/news']],
//        ['label' => Yii::t('app', 'api开发帮助文档'), 'url' => ['/site/api-helper-doc']],
    ];
    if (YII_ENV == 'dev') $menuItems[] = ['label' => Yii::t('app', 'webapi快速开发文档'), 'url' => '/webapi/index-dev.php/route/api'];
    if (Yii::$app->user->isGuest) {
        $menuItems[] = ['label' => Yii::t('app', 'Signup'), 'url' => ['/site/signup']];
        $menuItems[] = ['label' => Yii::t('app', 'Login'), 'url' => ['/site/login']];
    } else {
        $iden_user = Yii::$app->user->identity;
        $menuItems[] = ['label' => Yii::t('app', 'gii'), 'url' => ['/gii'], 'visible' => YII_ENV != 'prod' && $iden_user->is_super, 'linkOptions' => ['target' => '_blank']];
        $menuItems[] = [
            'label' => $iden_user->getAvatarImg(25, 25, ['class' => 'img img-responsive img-circle', 'style' => ['float' => "left"]]),
            'items' => [
                ['label' => "个人主页[{$iden_user->profileName}]", 'url' => $iden_user->profileUrl],
//                ['label' => '帐号设置', 'url' => ['/user/setting']],
                ['label' => '后台', 'url' => \common\config\Env::getUrls()['admin_url'],],
                ['label' => '退出', 'url' => ['/site/logout'], 'linkOptions' => ['data-method' => 'post']],
            ],
            'linkOptions' => [
                'class' => 'avatar',
            ],
        ];
    }
    echo Nav::widget([
        'options' => ['class' => 'navbar-nav navbar-right'],
        'items' => $menuItems,
        'encodeLabels' => false,
    ]);
    NavBar::end();
    ?>
    <?= $content ?>
</div>

<footer class="footer">
    <div class="container">
        <p class="pull-left">&copy; <?= Yii::$app->name ?> <?= date('Y') ?></p>
        <p class="pull-right"><?= Yii::powered() ?></p>
    </div>
</footer>

<?= ScrollTop::widget() ?>

<?php
if (Yii::$app->user->isGuest) {
    Modal::begin([
        'id' => 'login-box',
        'header' => '<h4 class="modal-title">登陆</h4>',
        'footer' => '<a href="#" class="btn btn-primary" data-dismiss="modal">关闭</a>',
        'options' => [],
    ]);
    $requestUrl = Url::toRoute(['/site/login', 'back_url' => Yii::$app->request->url]);
    $js = <<<JS
    $.get('{$requestUrl}', {},
        function (data) {
            $('.modal-body').html(data);
        }  
    );
JS;
    $this->registerJs($js);
    Modal::end();
}
?>

<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
